/*  
 * Copyright (C) 2011 Marta Spodymek
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *  
 */
package org.prometheuscode.web.feedback;

import javax.servlet.ServletContext;

import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

/**
 * Class defines global configuration for application.
 * 
 * @author marta
 * 
 */
@Component
public class ApplicationConfig implements ServletContextAware {

    /*
     * Pages default constants.
     */

    private final static String DEFAULT_ROOT_PAGES_DIR = "WEB-INF";

    private final static String DEFAULT_FORMS_DIR = "forms";

    private final static String DEFAULT_PAGES_DIR = "jsp";

    private final static String DEFAULT_PAGES_EXT = "jspx";

    private final static String DEFAULT_FORMS_EXT = "jsp";

    private final static String DEFAULT_INPUT_VALUE_SEPARATOR = "-^_^-";

    private final static String DEFAULT_CONTENT_PAGE_KEY = "contentPage";

    private final static String DEFAULT_MAIN_TEMPLATE_NAME = "mainTemplate";

    /*
     * Properties of application.
     */

    private ServletContext servletContext;

    private String inputValueSeparator = DEFAULT_INPUT_VALUE_SEPARATOR;

    private String mainTemplateName = DEFAULT_MAIN_TEMPLATE_NAME;

    private String contentPageName = DEFAULT_CONTENT_PAGE_KEY;

    private String pagesRootDir = DEFAULT_ROOT_PAGES_DIR;

    private String formsDir = DEFAULT_FORMS_DIR;

    private String pagesDir = DEFAULT_PAGES_DIR;

    private String pagesExt = DEFAULT_PAGES_EXT;

    private String formsExt = DEFAULT_FORMS_EXT;

    public ApplicationConfig() {
    }

    @Override
    public void setServletContext(ServletContext context) {
	this.servletContext = context;

    }

    public ServletContext getServletContext() {
	return this.servletContext;
    }

    public String getInputValueSeparator() {
	return this.inputValueSeparator;
    }

    public void setInputValueSeparator(String separator) {
	this.inputValueSeparator = separator;
    }

    /**
     * @return the mainTemplateName
     */
    public String getMainTemplateName() {
	return mainTemplateName;
    }

    /**
     * @param mainTemplateName
     *            the mainTemplateName to set
     */
    public void setMainTemplateName(String mainTemplateName) {
	this.mainTemplateName = mainTemplateName;
    }

    /**
     * @return the contentPageName
     */
    public String getContentPageName() {
	return contentPageName;
    }

    /**
     * @param contentPageName
     *            the contentPageName to set
     */
    public void setContentPageName(String contentPageName) {
	this.contentPageName = contentPageName;
    }

    /**
     * @return the pagesrootdir
     */
    public String getPagesRootDirectory() {
	return this.pagesRootDir;
    }

    /**
     * @return the formsdir
     */
    public String getFormsDirectory() {
	return this.formsDir;
    }

    /**
     * @return the pagesdir
     */
    public String getPagesDirectory() {
	return this.pagesDir;
    }

    /**
     * @return the pagesext
     */
    public String getPagesExtension() {
	return this.pagesExt;
    }

    /**
     * @return the formsext
     */
    public String getFormsExtension() {
	return this.formsExt;
    }

    public String getPagePath(String pageName) {
	return String.format("/%1$s/%2$s/%3$s.%4$s", this.pagesRootDir,
		this.pagesDir, pageName, this.pagesExt);
    }

    public String getFormPath(String formName) {
	return String.format("/%1$s/%2$s/%3$s.%4$s", this.pagesRootDir,
		this.formsDir, formName, this.formsExt);
    }

}
